#include "selectServer.hpp"
#include <memory>


int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        std::cerr << "Usage: " << argv[0] << " local-port" << std::endl;
        exit(0);
    }
    else if (argc == 3)
    {
        FILE *fp;
        if (argv[2] == std::string("i"))
        {
            fp = fopen("./dict.txt", "a+");
            while (true)
            {
                std::string english;
                std::string chinese;
                std::string entry;

                std::cout << "Enter english firstly # ";
                getline(std::cin, english);
                if (english == std::string("ok"))
                {
                    break;
                }
                std::cout << "Enter chinese # ";
                getline(std::cin, chinese);
                entry = english;
                entry += ": ";
                entry += chinese;
                fprintf(fp, "%s", "\n");
                fprintf(fp, "%s", entry.c_str());
            }
            fclose(fp);
        }
        else
        {
            std::cerr << "Usage: " << argv[0] << " local-port " << "i" << std::endl;
            exit(0);
        }
    }

    uint16_t port = std::stoi(argv[1]);

    EnableScreen();

    std::unique_ptr<selectServer> svr = std::make_unique<selectServer>(port);
    svr->initServer();
    svr->loop();

    return 0;
}
